package com.xiaochong.tir.apiservice.component;

import akka.actor.UntypedActor;
import com.alibaba.fastjson.JSON;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.tir.apiservice.util.SpringContextUtil;
import com.xiaochong.tir.common.data.hbasepo.*;
import com.xiaochong.tir.common.util.AkkaParamUtils;
import com.xiaochong.tir.common.util.CollectionUtil;
import com.xiaochong.tir.common.util.LogTraceKeysUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by wujiaxing on 2018/5/7.
 */
public class AkkaConceptIndex extends UntypedActor {


    private CmcDataCalculateComponent cmcDataCalculateComponent =
            (CmcDataCalculateComponent) SpringContextUtil.getBean("cmcDataCalculateComponent");


    @Override
    public void onReceive(Object o) {
        LogTrace.beginTrace("概念指数计算");
        Object o1 = ((Object[]) o)[0];
        Map<String, CmcCurrencyInfo> cmcMap = (Map<String, CmcCurrencyInfo>) o1;
        LogTrace.info(LogTraceKeysUtils.AKKA_CONCEPT_INDEX_TITLE, LogTraceKeysUtils.DATA,"概念指数计算开始");
        try{
            List<ConceptIndex> conceptIndices = cmcDataCalculateComponent.calculateConceptIndex(cmcMap);
            if(CollectionUtil.isNotBlank(conceptIndices)){
                cmcDataCalculateComponent.saveConceptIndex(conceptIndices);
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error(e.getMessage(), e);
        }

        LogTrace.info(LogTraceKeysUtils.AKKA_CONCEPT_INDEX_TITLE, LogTraceKeysUtils.DATA, "概念指数计算完成");
        LogTrace.endTrace();
    }
}
